package com.cxria.pattern.commandAndResponsibilityChain

abstract class CommandName {

    private CommandName nextOperator

    final String handleMessage(CommandVO vo){
        String result = ''
        if(vo.param.size() == 0 || vo.param.contains(getOperateParam())){
            result = echo(vo)
        } else {
            if(nextOperator){
                result = nextOperator.handleMessage(vo)
            } else {
                result = '命令无法执行'
            }
        }
        result
    }

    protected abstract String getOperateParam()

    protected abstract String echo(CommandVO vo)

    void setNext(CommandName operator){
        nextOperator = operator
    }

}
